<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入vue -->
     <script src="js/vue.js"></script>
     <!-- 引入elementui -->
      <!-- 样式 -->
    <link rel="stylesheet" href="element-ui-2.13.0/lib//theme-chalk/index.css">   
       <!-- 组件库 -->
    <script src="element-ui-2.13.0/lib/index.js"></script>  
    <script src="./js/axios-0.18.0.js"></script>  
</head>
<body>
    <div id="app">
        <template>
            <el-table
              :data="userList"
              style="width: 80%">
              <el-table-column
                prop="sid"
                label="序号"
                width="50">
              </el-table-column>
              <el-table-column
                prop="sname"
                label="姓名"
                width="150">
              </el-table-column>
              <el-table-column
                prop="sex"
                label="性别"
                width="50">
              </el-table-column>
              <el-table-column
                label="生日"
                width="200">
                <!--
                slot-scope="scope"  作用域插槽  用属性将当前行组件信息赋值给scope
                @click="handleEdit(scope.$index, scope.row)" 点击修改触发handleEdit函数
                            scope.$index  代表索引 从0开始，第一条数据的索引为0
                            scope.row     代表的是当前行的数据
                -->
                <template slot-scope="scope">
                    {{scope.row.sbir.substring(0,10)}}
                </template>
              </el-table-column>
              <el-table-column
                prop="hobby"
                label="爱好"
                width="200">
              </el-table-column>
              <el-table-column
                label="头像"
                width="150">
                <template slot-scope="scope">
                    <img :src=`${picUrl}/${scope.row.photo}` width="50px">
                </template>
              </el-table-column>
            </el-table>
        </template>

        <template>
           
            <div class="block">
              <!-- 
                :total="1700" 绑定总条数
                :current-page="currentPage4" 显示的当前页
                :page-sizes="[100, 200, 300, 400,500]" 页面可以切换的条数
                :page-size="100"  页面默认显示的条数
                @size-change="handleSizeChange" 条数改变触发的钩子函数
                 @current-change="handleCurrentChange" 当前页改变触发的钩子

                 layout="total, sizes, prev, pager, next, jumper" 组件布局，子组件名用逗号分隔
                    total 总条数
                    sizes 条数切换
                    prev 处理上一页
                    next 处理下一页
                    pager 页面显示的页码数
                    jumper 处理跳页
              -->
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[3, 4, 5, 6]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalSize">
              </el-pagination>
            </div>
          </template>
    </div>
</body>
</html>
<script>
    new Vue({
        el: '#app',
        methods: {
            handleSizeChange(val) {
                //val代表改变的条数
                console.log(`每页 ${val} 条`);
                this.pageSize = val
                this.findAll()
            },
            handleCurrentChange(val) {
                //val代表改变的当前页
                console.log(`当前页: ${val}`);
                this.currentPage = val
                this.findAll()
            },
            findAll(){
                let params = new URLSearchParams();
                params.append("currentPage",this.currentPage);
                params.append("mark","pageQuery");
                params.append("pageSize",this.pageSize);
                axios({
                    method:'get',
                    url: `${this.url}`,
                    responseType: 'json',
                    params:params
                }).then(resp => {
                    this.userList = resp.data.dataList
                    this.totalSize = resp.data.totalSize
                }).catch(_ => {
                    this.$message.error("分页查询错误！");
                })
            }
        },
        data:{
            currentPage:1,
            url:'http://localhost:8080/day22/student',
            picUrl:'http://localhost:8080/studentPic',
            pageSize:3,
            totalSize:0,
            userList:[]
        },
        created(){
            this.findAll();
        }
    })
</script>